package com.qdsgjsfk.vision.util;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.qdsgjsfk.vision.ui.LoginActivity;
import com.rest.converter.ApiException;

import jz.joyoung.robot.util.LogUtil;

/**
 * Created by HP on 2019/12/5.
 */

public class NetUtil {

    public static void onError(Throwable e, Context context) {
        try {
            if (e instanceof ApiException) {
                String errorMessage = ((ApiException) e).errorMessage;
                if (!UtilString.isEmpty( errorMessage )) {
                    Toast.makeText( context, errorMessage, Toast.LENGTH_SHORT ).show();
                }
                if (((ApiException) e).mErrorCode == 600 || ((ApiException) e).mErrorCode == 601 || ((ApiException) e).mErrorCode == 602 || ((ApiException) e).mErrorCode == 603 || ((ApiException) e).mErrorCode == 605 || ((ApiException) e).mErrorCode == 612 || ((ApiException) e).mErrorCode == 614 || ((ApiException) e).mErrorCode == 615) {
                    context.startActivity( new Intent( context, LoginActivity.class ) );
                }
            } else {
                LogUtil.e( "异常----", e.getMessage() );
//                Toast.makeText( context, "网络不佳，请切换网络后重试", Toast.LENGTH_SHORT ).show();
            }
        } catch (Exception exception) {
            e.printStackTrace();
        }


    }


}
